package de.hmm.hwip.security.service;

import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import android.util.Log;
import de.hmm.hwip.security.api.ISecurityClient;
import de.hmm.hwip.security.api.ISecurityServer;


/**
 * OSGi Service to provide security service
 * 
 * @author johannes mendel
 * @version 30.10.2012
 */
public class Activator implements BundleActivator {
	
	/** Class identifier to debug **/
	final String TAG = "Security Service Activator";
	
	/** osgi Security service interface */
	private ISecurityServer ssecuService;
	
	/** osgi Security service interface */
	private ISecurityClient csecuService;
	
	@Override
	public void start(BundleContext context) throws Exception {
		Log.i(TAG, "==========> Security Service started <==========");
		
		ssecuService = new ServerSecurityImpl();
		csecuService = new ClientSecurityImpl();
        
		//register the server security service @ osgi bundlecontext
		Hashtable<String, Object> ssecuparams = new Hashtable<String, Object>();
        ssecuparams.put( org.osgi.framework.Constants.SERVICE_PID, ISecurityServer.class.getName());
        ssecuparams.put( org.osgi.framework.Constants.SERVICE_DESCRIPTION, "Provides Server Security Service");
        context.registerService(ISecurityServer.class.getName(), ssecuService, ssecuparams);
        
        
        //register the server security service @ osgi bundlecontext
        Hashtable<String, Object> csecuparams = new Hashtable<String, Object>();
        csecuparams.put( org.osgi.framework.Constants.SERVICE_PID, ISecurityClient.class.getName());
        csecuparams.put( org.osgi.framework.Constants.SERVICE_DESCRIPTION, "Provides Client Security Service");
        context.registerService(ISecurityClient.class.getName(), csecuService, csecuparams);

	}

	@Override
	public void stop(BundleContext arg0) throws Exception {
		Log.i(TAG, "<========== !!! Security Service stopped !!! ==========>");

	}

}
